improvement(mothership): streaming state transitions#4439
improvement(mothership): streaming state transitions#4439icecrasher321 merged 3 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Hardens Updates task-event handling to invalidate/remove the right React Query caches (including detail on relevant events) while avoiding detail invalidation when a status event is stale relative to an optimistic/newer active stream; expands tests to cover these race cases. Reviewed by Cursor Bugbot for commit b8d76f9. Configure here. |
Greptile SummaryThis PR improves streaming state transitions in the mothership chat UI by: (1) adding Supporting infrastructure includes Confidence Score: 5/5Safe to merge — no P0/P1 issues found; two P2 observations on abort-signal hygiene. All findings are P2. The resolveChatIdForStream inside stopBarrier is bounded by its own internal 10 s timeout so it cannot hang indefinitely; the combineAbortSignals cleanup-listener ordering issue is a minor GC concern with no observable data-loss path. Core logic for stream recovery, cache invalidation, and cross-tab handoff is correct and well-tested. use-chat.ts — the stopBarrier in stopGeneration (queued-handoff branch) and combineAbortSignals helper are worth a second read for abort-hygiene completeness. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as Browser Tab
participant useChat as useChat hook
participant SSE as SSE Stream
participant Server as Server (API)
participant Redis as Redis/Pub-Sub
participant OtherTab as Other Tab (sessionStorage)
Note over UI,OtherTab: Normal streaming flow
UI->>useChat: sendMessage()
useChat->>Server: POST /stream
Server-->>SSE: stream events
SSE-->>useChat: processSSEStream (live)
Server->>Redis: publishStatus(started, streamId)
Redis-->>useChat: task_status SSE (streamId)
useChat->>useChat: shouldSkipDetailInvalidation?
Note over UI,OtherTab: Tab switch / visibility recovery
UI->>useChat: visibilitychange / pageshow / online
useChat->>useChat: recoverActiveStreamFromRedis()
useChat->>useChat: cancelActiveStreamReader()
useChat->>Server: fetchStreamBatch(afterCursor)
Server-->>useChat: batch events + chatId
useChat->>SSE: attachToExistingStream (resume)
SSE-->>useChat: processSSEStream (resume)
Note over UI,OtherTab: Queued message during active stream
UI->>useChat: sendMessage() [while streaming]
useChat->>useChat: createQueuedMessage(+handoff)
useChat->>useChat: stopGeneration(queued-handoff)
useChat->>Server: POST /abort (streamId)
alt chatId unknown
useChat->>Server: resolveChatIdForStream (poll)
Server-->>useChat: chatId resolved
end
Server->>Redis: publishStatus(completed, streamId)
Redis-->>useChat: task_status SSE
useChat->>useChat: shouldSkipDetailInvalidation?
useChat->>Server: POST /stream (new message)
Note over UI,OtherTab: Cross-tab handoff recovery
UI->>OtherTab: writeQueuedSendHandoffState (sessionStorage)
OtherTab->>OtherTab: writeQueuedSendHandoffClaim (ownerId)
OtherTab->>useChat: resolveChatIdForStream
OtherTab->>Server: POST /stream (recovered message)
Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile |
|
bugbot run |
|
@greptile |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b8d76f9. Configure here.
Summary
Improve streaming state transitions and fix issues like switching tabs leading to odd stream UIs.
Type of Change
Testing
Tested manually
Checklist